import datetime


class ContextError(Exception):
    """带上下文信息的异常类"""
    code = None
    message = None

    def __init__(self, *args, **context):
        self.context = {"code": self.code, 'message': self.message, "context": context if context else None,
                        'system_context': args}
        timestamp = datetime.datetime.now().isoformat()
        context_str = ", ".join(f"{k}={v}" for k, v in context.items())
        super().__init__(f"[{self.code}-{self.message}]-[上下文: {context_str}]-[时间: {timestamp}]")


class UnknownError(ContextError):
    code = 999
    message = '未知异常'


class FunctionNotExistError(ContextError):
    code = 7001
    message = '不存在该方法'





if __name__ == '__main__':
    try:
        user_id = 123
        raise UnknownError(
            user_id=user_id,
            action="delete",
            resource="account"
        )
    except ContextError as e:
        print(f"错误信息: {e.message}")

        print(e)
